﻿using SAP.Middleware.Connector;
using Sie.eMES.ThinClient.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApplication1.ServiceReference1;



namespace WindowsFormsApplication1
{

    public partial class Form1 : Form
    {
        public SapPersistBrokers sapProviders = null;
        public Form1()
        {
            InitializeComponent();

            // OnloadGirdTitle(this.dataGridView1);
        }
        public string weburl { get; set; }
        /// <summary>
        /// 明细表
        /// </summary>
        public DataTable dt_item { get; set; }
        private void button1_Click(object sender, EventArgs e)
        {
            // Class1 a = new Class1();
            //GetDataTable();

            //WindowsFormsApplication1.ServiceReference1.SmeeServiceSoapClient pack = new SmeeServiceSoapClient();
            //DataTable dt = pack.UpLoadSAP(dt_item, "SIE");
            ss();
        }

        public void ss()
        {
            GetDataTable();
            DataTable info = null;
            try
            {
                info = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "UpLoadSAP", new object[] { dt_item, "SIE", "SIE", "ASN160229002" });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }
        public void GetDataTable()
        {
            dt_item = new DataTable();
            dt_item.TableName = "tbl";

            //批次号
            List<string> p_batchno = new List<string>();
            //PO行
            List<string> p_poline = new List<string>();
            //货位
            List<string> p_invloc = new List<string>();
            //数量
            List<string> p_actqty = new List<string>();
            //物料号
            List<string> p_itemcode = new List<string>();
            // PO订单号
            List<string> p_ponumber = new List<string>();
            //ASN编码
            List<string> p_asncode = new List<string>();
            //销售订单
            List<string> p_salescode = new List<string>();
            //销售订单项目
            List<string> p_salesproject = new List<string>();
            //生产日期
            List<string> p_outdate = new List<string>();
            //版本
            List<string> p_mversion = new List<string>();

            List<string> pAsncount = new List<string>();
            List<string> pSumAlrQty = new List<string>(); //分组之和
            List<string> pCurrentqty = new List<string>(); //ASN数量



            dt_item.Columns.Add(new DataColumn("barcode", typeof(string)));
            dt_item.Columns.Add(new DataColumn("ponumber", typeof(string)));
            dt_item.Columns.Add(new DataColumn("poline", typeof(decimal)));
            //SAP 上传信息
            dt_item.Columns.Add(new DataColumn("itemcode", typeof(string)));
            dt_item.Columns.Add(new DataColumn("unit", typeof(string)));
            dt_item.Columns.Add(new DataColumn("AlrQty", typeof(string)));//有销售订单就为1，否为空
            dt_item.Columns.Add(new DataColumn("salescode", typeof(string)));//组织ID
            dt_item.Columns.Add(new DataColumn("salesproject", typeof(decimal)));//未收货数量
            dt_item.Columns.Add(new DataColumn("locid", typeof(decimal)));//采购数量
            dt_item.Columns.Add(new DataColumn("vendorname", typeof(string))); //单位
            dt_item.Columns.Add(new DataColumn("itemdescription", typeof(string)));//库存地点
            dt_item.Columns.Add(new DataColumn("RecQty", typeof(string)));//采购凭证中的项目类别
            dt_item.Columns.Add(new DataColumn("count", typeof(string)));//生产日期
            dt_item.Columns.Add(new DataColumn("mversion", typeof(string)));//供应商
            dt_item.Columns.Add(new DataColumn("asncode", typeof(string)));//科目分配类别
            dt_item.Columns.Add(new DataColumn("sumcurrentqty", typeof(string)));//销售订单
            dt_item.Columns.Add(new DataColumn("currentqty", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("sobkz", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("orgid", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("zwshl", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("quantity", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("storagelocation", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("pstyp", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("outdate", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("vendorcode", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("knttp", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("vbeln", typeof(string)));//销售订单行项目
            dt_item.Columns.Add(new DataColumn("batchcode", typeof(string)));//销售订单行项目

            DataRow row = dt_item.NewRow();
            p_batchno.Add("16030900003");
            p_poline.Add("20");
            p_invloc.Add("40001");
            p_actqty.Add("1");
            pCurrentqty.Add("29");
            p_itemcode.Add("502010214007");
            p_ponumber.Add("4500012198");
            p_asncode.Add("ASN160309002");
            p_salescode.Add("");
            p_salesproject.Add("");
            p_outdate.Add("20160303");
            p_mversion.Add("I");
            pAsncount.Add("1");
            pSumAlrQty.Add("1");

            row["barcode"] = "16030900003";
            row["ponumber"] = "4500012198";
            row["poline"] = "20";
            row["itemcode"] = "502010214007";
            row["unit"] = "PCS";
            //begin SAP信息
            row["AlrQty"] = "1";
            row["locid"] = "40001";
            row["vendorname"] = "东莞市信懋塑胶实业有限公司";
            row["itemdescription"] = "CRM9250循环钱箱B95(英文)";
            row["RecQty"] = "7";//采购凭证中的项目类别
            row["count"] = "";//生产日期
            row["mversion"] = "I";//供应商
            row["asncode"] = "ASN160309002";//科目分配类别
            row["sumcurrentqty"] = "50";//销售订单
            row["currentqty"] = "32";//销售订单行项目
            row["sobkz"] = "1";//销售订单行项目
            row["orgid"] = "1000";//销售订单行项目
            row["zwshl"] = "379";//销售订单行项目
            row["quantity"] = "400";//销售订单行项目
            row["storagelocation"] = "G301";//销售订单行项目
            row["pstyp"] = "3";//销售订单行项目
            row["outdate"] = "20160309";//销售订单行项目
            row["vendorcode"] = "200022";//销售订单行项目
            row["knttp"] = "M";//销售订单行项目
            row["vbeln"] = "";//销售订单行项目
            row["batchcode"] = "";//销售订单行项目
            //end

            dt_item.Rows.InsertAt(row, 0);
            dt_item.AcceptChanges();
            websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "FSupplierDeliveryPost", new object[] { 1000,
                                    p_batchno.ToArray(),
                                    p_poline.ToArray(),  //PO行
                                    p_invloc.ToArray(),  //货位
                                    p_actqty.ToArray(), //数量
                                    pCurrentqty.ToArray(),
                                    p_itemcode.ToArray(), //物料号
                                    p_ponumber.ToArray(),// PO订单号
                                    p_asncode.ToArray(), //ASN编码
                                    p_salescode.ToArray(),//销售订单
                                    p_salesproject.ToArray(),//销售订单项目
                                    pAsncount.ToArray(),
                                    pSumAlrQty.ToArray(),
                                    p_outdate.ToArray(),//生产日期
                                    p_mversion.ToArray(),  //版本
                                    "SIE",
                                    dt_item,
                                     "SIE",
                                    "16030900003" });



        }

        private void button2_Click(object sender, EventArgs e)
        {
            dt_item = new DataTable();
            dt_item.TableName = "tbl";

            dt_item.Columns.Add(new DataColumn("MBLNR", typeof(string)));
            dt_item.Columns.Add(new DataColumn("ZEILE", typeof(string)));
            dt_item.Columns.Add(new DataColumn("MJAHR", typeof(string)));
            dt_item.Columns.Add(new DataColumn("AlrQty", typeof(string)));
            DataRow row = dt_item.NewRow();
            row["MBLNR"] = "5000000264";
            row["ZEILE"] = "1";
            row["MJAHR"] = "2016";
            row["AlrQty"] = "1";

            dt_item.Rows.InsertAt(row, 0);
            dt_item.AcceptChanges();

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                DataTable dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "ReturnMimteSAP", new object[] { dt_item, "SIE", "SIE" });
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                string msg = websv.InvokeWebservice<string>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "IQCExamine", new object[] { textBox1.Text.Trim(), textBox3.Text.Trim(), textBox2.Text.Trim(), textBox4.Text.Trim(), "SIE", textBox5.Text.Trim() });
                textBox5.Text = msg;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                decimal upqty = Convert.ToDecimal(string.IsNullOrEmpty(textBox7.Text.Trim()) ? "0" : textBox7.Text);

                if (upqty == 0)
                {
                    MessageBox.Show("请输入上架数量");
                    textBox7.Focus();
                    return;
                }
                string msg = websv.InvokeWebservice<string>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "StorageOrReturn", new object[] { textBox10.Text.Trim(), textBox8.Text.Trim(), textBox9.Text.Trim(), textBox7.Text.Trim(), textBox11.Text.Trim(), textBox12.Text });

                textBox13.Text = msg;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                decimal qty = Convert.ToDecimal(string.IsNullOrEmpty(textBox11.Text.Trim()) ? "0" : textBox11.Text);
                if (qty == 0)
                {
                    MessageBox.Show("请输入上架数量");
                    textBox11.Focus();
                    return;
                }
                string msg = websv.InvokeWebservice<string>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "StorageOrReturn", new object[] { textBox10.Text.Trim(), textBox8.Text.Trim(), textBox9.Text.Trim(), textBox7.Text.Trim(), textBox11.Text.Trim(), textBox12.Text });
                textBox13.Text = msg;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            GetDataTable();

        }
        /// <summary>
        /// 绑定表头
        /// </summary>
        /// <param name="gdview"></param>
        private void OnloadGirdTitle(DataGridView gdview)
        {
            string[] titles = new string[] { "barcode=标签号", "qty=数量" };
            DataGridViewController.SetDefaultLayout(gdview, titles, false);



        }

        private void button2_Click_1(object sender, EventArgs e)
        {

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (dataGridView1.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        if (dataGridView1.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView1.Rows[i].Cells[0].Value, dataGridView1.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    if (dtitem.Rows.Count > 0)
                    {
                        dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "update_mes_material_label", new object[] { dtitem, "SIE", "1000", "SIE" });
                    }
                    textBox14.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "上传成功：凭证号" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();

                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //RfcDestination rd = this.sapProviders.GetRfcDes();
            //RfcRepository rfcrep = rd.Repository;
            //DataTable dt;
            //dt = new DataTable();
            //dt.Columns.Add("HARDWARE");
            //dt.Columns.Add("HARDWARETYPE");
            //dt.Columns.Add("MITEMNAME");
            //dt.Columns.Add("ATTRIBUTE1");
            //dt.Columns.Add("ORGID");
            //IRfcFunction myfun = null;
            //myfun = rfcrep.CreateFunction("ZZERP_MES_031");
            //myfun.SetValue("B_DATE", string.Format("{0:yyyyMMdd}", DateTime.Now));//SAP里面的传入参数
            //myfun.SetValue("E_DATE", string.Format("{0:yyyyMMdd}", DateTime.Now));

            ////myfun.SetValue("B_DATE", "20131001");//SAP里面的传入参数
            ////myfun.SetValue("E_DATE", "20150930");
            //myfun.Invoke(rd);
            //IRfcTable IrfTable = myfun.GetTable("EX_TABLE");

            //for (int i = 0; i < IrfTable.Count; i++)
            //{
            //    IrfTable.CurrentIndex = i;
            //    DataRow dr = dt.NewRow();
            //    dr["HARDWARE"] = IrfTable.GetString("REVLV");
            //    dr["HARDWARETYPE"] = IrfTable.GetString("AETYP");
            //    dr["MITEMNAME"] = IrfTable.GetString("OBJKT");
            //    dr["ATTRIBUTE1"] = IrfTable.GetString("OITXT");
            //    dr["ORGID"] = 1000;
            //    //dt.Columns.Add("");

            //    dt.Rows.Add(dr);
            //}
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //  sapProviders = new SapPersistBrokers();
            comboBox3.SelectedIndex = 0;
            this.WindowState = FormWindowState.Maximized;
            weburl = "http://10.1.1.140/SmeeWebService";
        }



        private void button6_Click_1(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (dataGridView2.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView2.Rows.Count; i++)
                    {
                        if (dataGridView2.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView2.Rows[i].Cells[0].Value, dataGridView2.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    //if (dtitem.Rows.Count > 0)
                    //{
                    //    dt = pack.OutsourceInterface(dtitem,"1000", "SIE","SIE" );
                    //}
                    if (dt != null)
                        textBox15.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "上传成功：凭证号" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();
                    else
                        textBox15.Text = "标签不存在或未发布到SAP系统！";
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (dataGridView3.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView3.Rows.Count; i++)
                    {
                        if (dataGridView3.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView3.Rows[i].Cells[0].Value, dataGridView3.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    if (dtitem.Rows.Count > 0)
                    {
                        dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "return_material_label", new object[] { dtitem, "SIE", "1000", "SIE", "退料" });
                    }
                    if (dt != null)
                        textBox16.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "提交成功：" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();
                    else
                        textBox16.Text = "标签不存在或未发布到SAP系统！";
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (dataGridView4.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView4.Rows.Count; i++)
                    {
                        if (dataGridView4.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView4.Rows[i].Cells[0].Value, dataGridView4.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    if (dtitem.Rows.Count > 0)
                    {
                        dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "return_material_label", new object[] { dtitem, "SIE", "1000", "SIE", "报废" });

                    }
                    if (dt != null)
                        textBox17.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "提交成功：" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();
                    else
                        textBox17.Text = "标签不存在或未发布到SAP系统！";
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                textBox19.Text = websv.InvokeWebservice<string>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "ZZERP_MES_CBT",
                    new object[] { textBox18.Text.Trim(), "0", "SIE", "SIE", "1000" });
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

        }

        private void button10_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                textBox20.Text = websv.InvokeWebservice<string>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "ZZERP_MES_CBT",
                    new object[] { textBox21.Text.Trim(), "1", "SIE", "SIE", "1000" });
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (dataGridView5.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView5.Rows.Count; i++)
                    {
                        if (dataGridView5.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView5.Rows[i].Cells[0].Value, dataGridView5.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    if (dtitem.Rows.Count > 0)
                    {
                        string a = string.Empty;
                        switch (comboBox1.Text)
                        {
                            case "外协转出":
                                a = "ZTO";
                                break;
                            case "外协转入":
                                a = "ZTI";
                                break;
                            case "库存转储":
                                a = "ZTF";
                                break;
                            case "成本中心领料":
                                a = "ZCL";
                                break;
                            case "成本中心退料":
                                a = "ZCT";
                                break;

                        }
                        //WindowsFormsApplication1.ServiceReference1.SmeeServiceSoapClient pack = new SmeeServiceSoapClient();
                        //pack.ZZERP_MES_STRUCTURE_TRANS_CBT(dtitem, "dddd", a, "SIE", "SIE", "1000");
                        dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "ZZERP_MES_STRUCTURE_TRANS_CBT",
                    new object[] { dtitem, a, a, "SIE", "SIE", "1000" });
                    }
                    if (dt != null)
                        textBox22.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "提交成功,凭证号:" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();
                    else
                        textBox22.Text = "标签不存在或未发布到SAP系统！";

                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (dataGridView6.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView6.Rows.Count; i++)
                    {
                        if (dataGridView6.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView6.Rows[i].Cells[0].Value, dataGridView6.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    if (dtitem.Rows.Count > 0)
                    {
                        string a = string.Empty;
                        switch (comboBox2.Text)
                        {
                            case "外协转出":
                                a = "ZTO";
                                break;
                            case "外协转入":
                                a = "ZTI";
                                break;
                            case "库存转储":
                                a = "ZTF";
                                break;
                            case "成本中心领料":
                                a = "ZCL";
                                break;
                            case "成本中心退料":
                                a = "ZCT";
                                break;

                        }
                        //WindowsFormsApplication1.ServiceReference1.SmeeServiceSoapClient pack = new SmeeServiceSoapClient();
                        //pack.ZZERP_MES_STRUCTURE_TRANS_CBT(dtitem, "tblreturnmaterial", a, "SIE", "SIE", "1000");
                        dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "ZZERP_MES_STRUCTURE_TRANS_CBT",
                    new object[] { dtitem, "tblreturnmaterial", a, "SIE", "SIE", "1000" });
                    }
                    if (dt != null)
                        textBox23.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "提交成功,凭证号:" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();
                    else
                        textBox23.Text = "标签不存在或未发布到SAP系统！";
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox3.Text)
            {
                case "开发环境":
                    weburl = "http://10.1.1.140/SmeeWebService";
                    break;
                case "验证环境":
                    weburl = "http://10.1.1.140/SITwebService";
                    break;
                case "本机环境":
                    weburl = "http://localhost:2219/SmeeService.asmx";
                    break;
                //case "正式环境":
                //    weburl = "http://10.252.252.32/PDAwebService.asmx";
                //    break;
            }

        }

        private void button13_Click(object sender, EventArgs e)
        {
            
        }

        private void button14_Click(object sender, EventArgs e)
        {
            string val=textBox26.Text.Trim().Replace("<sapinfo>", "").Replace("</sapinfo>", "").Replace("\r\n", "").Trim();
            DataSet dtSet =
                XmlDatasetConvert.CXmlToDataSet(@"<?xml version='1.0' encoding='utf-8'?>" + "<sapinfo>" + val + "</sapinfo>" 
                );
            dataGridView7.DataSource = dtSet.Tables["info"];
            label31.Text = dtSet.Tables["info"].AsEnumerable().GroupBy(o => o[textBox27.Text.Trim()]).Count().ToString();
            label32.Text = dtSet.Tables["info"].AsEnumerable().Sum(o => Convert.ToDecimal(o[textBox28.Text.Trim()])).ToString();
        }

        public void OnloadBinddrow()
        {
            switch (comboBox3.Text)
            {
                case "开发环境":
                    weburl = "http://10.1.1.140/SmeeWebService";
                    break;
                case "验证环境":
                    weburl = "http://10.1.1.140/SITwebService";
                    break;
                case "本机环境":
                    weburl = "http://localhost:2219/SmeeService.asmx";
                    break;
                case "正式环境":
                    weburl = "http://10.252.252.32/PDAwebService.asmx";
                    break;
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                OnloadBinddrow();
                if (dataGridView8.Rows.Count > 0)
                {
                    DataTable dtitem;
                    dtitem = new DataTable();
                    dtitem.TableName = "dtReport1";
                    dtitem.Columns.Add(new DataColumn("barcode", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("mitemnamelab", typeof(string)));
                    dtitem.Columns.Add(new DataColumn("qty", typeof(string)));
                    for (int i = 0; i < dataGridView8.Rows.Count; i++)
                    {
                        if (dataGridView8.Rows[i].Cells[0].Value != null)
                            dtitem.Rows.Add(dataGridView8.Rows[i].Cells[0].Value, dataGridView8.Rows[i].Cells[1].Value);
                    }
                    DataTable dt = null;
                    if (dtitem.Rows.Count > 0)
                    {
                        dt = websv.InvokeWebservice<DataTable>(weburl, "Sie.eMES.ThinClient.WebService", "SmeeService", "ZZERP_MES_045Up", 
                            new object[] { dtitem,comboBox4.Text, "SIE",textBox30.Text.Trim(),"1000", "SIE" });

                    }
                    if (dt != null)
                        textBox29.Text = string.IsNullOrEmpty(dt.Rows[0]["MESSAGE"].ToString().Trim()) ? "提交成功：" + dt.Rows[0]["MBLNR"].ToString().Trim() : dt.Rows[0]["MESSAGE"].ToString().Trim();
                    else
                        textBox29.Text = "标签不存在或未发布到SAP系统！";
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

    }
}
